#include    "creditsscene.h"

#include    "../common.h"
#include    "../ui/button/button.h"
#include    "../font/fontmanager.h"
#include    "../picture/picture.h"
#include    "../ui/input/mouseinputmanager.h"
#include    "../audio/audio_engine.h"


Button* menuButton = 0;
SinglePictureRenderWrap* creditsBackgroundRendWrap = 0;


CreditsScene::CreditsScene(GameApp* app): AppScene(app)
{
    creditsBackgroundRendWrap = new SinglePictureRenderWrap("resources/credits.png",800.0f,600.0f);

    menuButton = new Button("resources/menuButton.png",75,38);
    menuButton->m_function = [this](int a,int b){ this->menuButtonClick(); };
    menuButton->setPosition(385,400);

    on();
}

CreditsScene::~CreditsScene()
{

    SAFE_DELETE_OBJ(menuButton);
    SAFE_DELETE_OBJ(creditsBackgroundRendWrap);

}

void CreditsScene::menuButtonClick()
{
    std::string button("button");
    AudioEngine::getInstance()->playSound(button);

    off();
    m_app->setGameState(GameApp::GAMESTATE_MENU);
}

void CreditsScene::on()
{
    if(switchOpen == true){return;}

    MouseInputManager::getInstance()->addClickable(menuButton);
    Switch::on();
}

void CreditsScene::off()
{
    MouseInputManager::getInstance()->removeAllClickable();
    Switch::off();
}

void CreditsScene::render()
{
#define TEXT_X  370
#define TEXT_Y  250
#define TEXT_SPACE      20
#define TEXT_HEIGHT     30

    creditsBackgroundRendWrap->render(0,0);
    menuButton->render();
    m_app->getFontManager()->drawText("Sater",TEXT_X,TEXT_Y,0,0,1);
    m_app->getFontManager()->drawText("Thank for you play",TEXT_X - 75,TEXT_Y + 2*TEXT_HEIGHT,0,0,1);
    m_app->getFontManager()->drawText("Book:<OpenGL.Game.Development.By.Example>",TEXT_X - 250,TEXT_Y + 4*TEXT_HEIGHT,0,0,1);

}

void CreditsScene::update(TimeSeconds deltalTime)
{

}
